<template>
  <div class="right_post">
    <div class="postList">
      <!-- <div class="posts" v-for="(item,index) in postList" :key="index"> -->
      <div class="posts">
        <!-- 判断图片长度 三张图片结构 -->
        <div v-if="item.images.length>=3">
          <div class="title" @click="toPostDetail(item)">{{item.title}}</div>
          <div class="content_text"  @click="toPostDetail(item)">{{item.summary}}</div>
          <div class="content_images1"  @click="toPostDetail(item)">
            <img class="postImg" :src="item.images[0]" alt/>
            <img class="postImg" :src="item.images[1]" alt/>
            <img class="postImg" :src="item.images[2]" alt/>
            <!-- <img class="postImg" :src="item.images[0]" alt :onerror="defaultImg"/>
            <img class="postImg" :src="item.images[1]" alt :onerror="defaultImg"/>
            <img class="postImg" :src="item.images[2]" alt :onerror="defaultImg"/> -->
          </div>
          <div class="bottom">
            <div class="bottom_left">
              <span class="iconfont icon-weizhi"></span>
              {{item.cityName}}
              <span
                :style="`margin-left:10px; margin-right:5px; `"
              >by</span>
              <div :style="`color:orange;`">
                <img
                  class="user"
                  :src="`${$axios.defaults.baseURL+item.account.defaultAvatar}`"
                  alt
                />
                {{item.account.nickname}}
              </div>
              <span class="iconfont icon-yanjing"></span>
              {{item.watch}}
            </div>
            <div class="bottom_right" v-if="item.like!=null">
              <a href="#">{{item.like}}赞</a>
            </div>
            <div class="bottom_right" v-else-if="item.like==null">
              <a href="#">0赞</a>
            </div>
          </div>
        </div>

        <!-- 一张图片结构 -->
        <div v-else-if="item.images.length<3 &item.images.length>0" class="imgOne">
        <!-- <div v-else-if="item.images.length>0 && item.images.length<3" class="imgOne"> -->
          <div class="content_images"  @click="toPostDetail(item)">
            <!-- 图片失效设置默认 -->
            <!-- <img class="postImg2" :src="item.images[0]" alt :onerror="defaultImg"/> -->
            <img class="postImg2" :src="item.images[0]" alt/>
          </div>
          <div class="right">
            <div class="title" @click="toPostDetail(item)">{{item.title}}</div>
            <div class="content_text" v-html="item.summary"  @click="toPostDetail(item)"></div>
            <!-- <div class="content_text">{{item.summary}}</div> -->
            <div class="bottom">
              <div class="bottom_left">
                <div>
                  <span class="iconfont icon-weizhi"></span>
                  {{item.cityName}}
                </div>
                <span :style="`margin-left:10px; margin-right:5px; `">by</span>
                <div :style="`color:orange;`">
                  <img
                    class="user"
                    :src="`${$axios.defaults.baseURL+item.account.defaultAvatar}`"
                    alt
                  />
                  {{item.account.nickname}}
                </div>
                <span class="iconfont icon-yanjing"></span>
                {{item.watch}}
              </div>
              <!-- 点赞 -->
              <div class="bottom_right" v-if="item.like!=null">
                <a href="#">{{item.like}}赞</a>
              </div>
              <div class="bottom_right" v-else-if="item.like==null">
                <a href="#">0赞</a>
              </div>
            </div>
          </div>
        </div>
        <!-- 没有图片的情况 -->
        <div v-else>
          <div class="title" @click="toPostDetail(item)">{{item.title}}</div>
          <div class="content_text"  @click="toPostDetail(item)">{{item.summary}}</div>
          <div class="bottom">
            <div class="bottom_left">
              <span class="iconfont icon-weizhi"></span>
              {{item.cityName}}
              <span
                :style="`margin-left:10px; margin-right:5px; `"
              >by</span>
              <div :style="`color:orange;`">
                <img
                  class="user"
                  :src="`${$axios.defaults.baseURL+item.account.defaultAvatar}`"
                  alt
                />
                {{item.account.nickname}}
              </div>
              <span class="iconfont icon-yanjing"></span>
              {{item.watch}}
            </div>
            <div class="bottom_right" v-if="item.like!=null">
              <a href="#">{{item.like}}赞</a>
            </div>
            <div class="bottom_right" v-else-if="item.like==null">
              <a href="#">0赞</a>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  props:["item"],
  data() {
    return {
      // defaultImg:'this.src="' +require('../../assets/images/03.jpg') +'"'
      // 存放文章列表
      postList:[]
    };
  },
  methods:{
    toPostDetail(data){
      // 获取文章id
      const {id} = data;
      this.$router.push({
        path:"/post/detail",
        query:{
          id
        }
      })     
    }
  }
};
</script>
<style lang="less" scoped>
.right_post {
  .postList {
    .posts {
      width: 100%;
      padding: 20px 0;
      border-bottom: 1px solid #eee;
    }
    .right {
      width: 470px;
    }

    .title {
      font-size: 20px;
      margin-bottom: 20px;
      white-space: nowrap;
      overflow: hidden;
      text-overflow: ellipsis;
      &:hover {
        color: orange;
      }
    }
    .content_text {
      color: #666;
      margin-bottom: 10px;
      text-overflow: -o-ellipsis-lastline;
      overflow: hidden;
      text-overflow: ellipsis;
      display: -webkit-box;
      -webkit-line-clamp: 3;
      -webkit-box-orient: vertical;
      // 内容少把底部顶下去
      height: 65px;
    }
    // 三张图片
    .content_images1 {
      display: flex;
      justify-content: space-between;
      box-sizing: border-box;
      align-items: center;
      .postImg {
        flex: 0 0 33%;
        width: 220px;
        height: 150px;
        margin-right: 10px;
        object-fit: cover;
      }
    }
    // 一张图片
    .imgOne {
      width: 100%;
      display: flex;
      justify-content: flex-start;
      .postImg2 {
        width: 220px;
        height: 150px;
        margin-right: 10px;
        object-fit: cover;
      }
    }
  }
  .bottom {
    display: flex;
    justify-content: space-between;
    margin-top: 20px;
    .bottom_left {
      display: flex;
      justify-content: flex-start;
      align-items: center;
      color: #666;
      font-size: 12px;
    }
    .bottom_right {
      color: orange;
    }
  }
  .user {
    width: 16px;
    height: 16px;
  }
  .iconfont {
    font-size: 14px;
    margin: 0 5px;
  }
}
</style>